// @before-stub-for-debug-begin
#include <vector>
#include <string>
#include <unordered_map>
#include "commoncppproblem169.h"

using namespace std;
// @before-stub-for-debug-end

/*
 * @FilePath: \undefinedc:\Users\sxjct\.leetcode\169.多数元素.cpp
 * @Brief: 
 * @Version: 1.0
 * @Date: 2021-04-09 10:31:41
 * @Author: tianyiyi
 * @Copyright: Copyright@tianyiyi
 * @LastEditors: Mr.Tian
 * @LastEditTime: 2021-04-09 10:40:36
 */
/*
 * @lc app=leetcode.cn id=169 lang=cpp
 *
 * [169] 多数元素
 */

// @lc code=start
class Solution {
public:
    int majorityElement(vector<int>& nums) {
        int n = nums.size()/2;
        unordered_map<int , int> map;
        for(int i = 0;i < nums.size();i++)
        {
            map[nums[i]]++;
            if(map[nums[i]]> n)
            {
                return nums[i];
            }
            
        }
        return nums[0];
    }
};
// @lc code=end

